<?php


namespace App\Http\Response;

trait ResponseJson
{

    /**
     * 当APP 接口出现业务异常时的返回
     * @param $code
     * @param $message
     * @param array $data
     * @return false|string
     */
    public function jsonData($code, $message, $data=[])
    {
        return $this->jsonResponse($code, $message, $data);
    }
    /**
     * App 接口请求成功时的返回
     * @param array $data
     * @return false|string
     */
    public function jsonSuccessData($data = []){
        return $this->jsonResponse(0, 'success', $data);
    }

    /**
     * 返回一个 json
     * @param $code
     * @param $message
     * @param array $data
     * @return false|string
     */
    private function jsonResponse($code, $message, $data = [])
    {
        $content = [
            'code' => $code,
            'msg' => $message,
            'data' => $data
        ];
        return json_encode($content);
    }
}
